﻿using System;
using System.Data;
using System.Collections.Generic;
using IPR_StudyMeetingMrgSys.Common;
using IPR_StudyMeetingMrgSys.Model;
using IPR_StudyMeetingMrgSys.DAL;

namespace IPR_StudyMeetingMrgSys.BLL
{
    /// <summary>
    /// TrainCourse
    /// </summary>
    public partial class TrainCourse
    {
        private readonly IPR_StudyMeetingMrgSys.DAL.TrainCourse dal = new IPR_StudyMeetingMrgSys.DAL.TrainCourse();
        public TrainCourse()
        { }
        #region  BasicMethod

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(IPR_StudyMeetingMrgSys.Model.TrainCourse model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(IPR_StudyMeetingMrgSys.Model.TrainCourse model, int? depLevel, out string errorMsg)
        {
            return dal.Update(model, depLevel, out errorMsg);
        }
        /// <summary>
        /// 课程更新教师
        /// </summary>
        public bool UpdateTeacher(string tcoid, string teacherid, string teachername)
        {
            return dal.UpdateTeacher(tcoid, teacherid, teachername);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long AutoID)
        {

            return dal.Delete(AutoID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string TCOIDlist)
        {
            return dal.DeleteList(TCOIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public IPR_StudyMeetingMrgSys.Model.TrainCourse GetModel(long TCOID)
        {

            return dal.GetModel(TCOID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public IPR_StudyMeetingMrgSys.Model.TrainCourse GetModelByCache(long AutoID)
        {

            string CacheKey = "TrainCourseModel-" + AutoID;
            object objModel = IPR_StudyMeetingMrgSys.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(AutoID);
                    if (objModel != null)
                    {
                        int ModelCache = IPR_StudyMeetingMrgSys.Common.ConfigHelper.GetConfigInt("ModelCache");
                        IPR_StudyMeetingMrgSys.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (IPR_StudyMeetingMrgSys.Model.TrainCourse)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<IPR_StudyMeetingMrgSys.Model.TrainCourse> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<IPR_StudyMeetingMrgSys.Model.TrainCourse> DataTableToList(DataTable dt)
        {
            List<IPR_StudyMeetingMrgSys.Model.TrainCourse> modelList = new List<IPR_StudyMeetingMrgSys.Model.TrainCourse>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                IPR_StudyMeetingMrgSys.Model.TrainCourse model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod
        /// <summary>
        /// 是否存在该记录,判断名称
        /// </summary>
        public bool Exists(long crid, string startdatetime, string enddatetime)
        {
            return dal.Exists(crid, startdatetime, enddatetime);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex, out int rowCount)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex, out rowCount);
        }
        /// <summary>
        /// 培训计划发布
        /// </summary>
        public bool Release(string TCOIDlist)
        {
            return dal.Release(TCOIDlist);
        }

        /// <summary>
        /// 获取当前教室最近的培训课程列表
        /// </summary>
        /// <param name="CRID"></param>
        /// <returns></returns>
        public DataSet GetNearestCourse(string CRID)
        {
            return dal.GetNearestCourse(CRID);
        }

        public string GetCourseStudy(string strWhere)
        {
            return dal.GetCourseStudy(strWhere);
        }
        public List<ReportCourseStudy> GetCourseStudyReaching(string strWhere, bool IsDuan,int? CurrentDepID)
        {
            return dal.GetCourseStudyReaching(strWhere,IsDuan,CurrentDepID);
        }

        #region 统计查询
        //车间 车队  培训课程次数  培训内容数量 
        public List<ReportCourseCount> GetCourseStudyCourseCount_Chejian(int? DepLevelId, int? CurrentDepID, DateTime startTime, DateTime endTime)
        {
            return dal.GetCourseStudyCourseCount_Chejian(DepLevelId,CurrentDepID,startTime,endTime);
        }
        public List<ReportCourseCount> GetCourseStudyCourseCount_Chedui(int? DepLevelId, int? CurrentDepID, DateTime startTime, DateTime endTime)
        {
            return dal.GetCourseStudyCourseCount_Chedui(DepLevelId, CurrentDepID, startTime, endTime);
        }
        public List<ReportCourseCount> GetCourseStudyCourseCount_Chengwuyuan(string chedui_Ids, DateTime startTime, DateTime endTime)
        {
            return dal.GetCourseStudyCourseCount_Chengwuyuan(chedui_Ids, startTime, endTime);
        }
        public List<ReportCourseCount> GetCourseStudyCourseCount_Content(string User_Id, DateTime startTime, DateTime endTime)
        {
            return dal.GetCourseStudyCourseCount_Content(User_Id, startTime, endTime);
        }

        public List<ReportCourseCount> GetCourseStudyCourseCount_StudyCount(string chedui_Ids, DateTime startTime, DateTime endTime,string personName)
        {
            return dal.GetCourseStudyCourseCount_StudyCount(chedui_Ids, startTime, endTime,personName);
        }
        public List<ReportCourseCount> GetCourseStudyCourseCount_CountNo(string chedui_Ids, DateTime startTime, DateTime endTime,string personName)
        {
            return dal.GetCourseStudyCourseCount_CountNo(chedui_Ids, startTime, endTime, personName);
        }
        public List<ReportCourseCount> GetCourseStudyCourseCount_ChengwuyuanCourseDetailCount(string User_Id, DateTime startTime, DateTime endTime)
        {
            return dal.GetCourseStudyCourseCount_ChengwuyuanCourseDetailCount(User_Id, startTime, endTime);
        }

        public List<ReportCoursePerson> GetCourseStudyCourse_uncommittedPerson(string chedui_Ids, DateTime startTime, DateTime endTime)
        {
            return dal.GetCourseStudyCourse_uncommittedPerson(chedui_Ids,startTime,endTime);
        }
        #endregion

        public List<ReportCourseCount> Get_CheduiList(int? DepLevelId, int? CurrentDepID)
        {
            return dal.Get_CheduiList(DepLevelId, CurrentDepID);
        }
        public List<ReportCourseCount> Get_ChejianList(int? DepLevelId, int? CurrentDepID)
        {
            return dal.Get_ChejianList(DepLevelId, CurrentDepID);
        }

        #region 查询 

        #region 查询学习了该课程的乘务员 学习记录
        public List<ReportCourseCount> GetCourseStudyCourseCount_ChengwuyuanStudyCourseRecorder(string TCOID)
        {
            return dal.GetCourseStudyCourseCount_ChengwuyuanStudyCourseRecorder(TCOID);
        }
        public List<long> AddList(IPR_StudyMeetingMrgSys.Model.TrainCourse model)
        {
            return dal.AddList(model);
        }
        #endregion
        #endregion

        #endregion  ExtensionMethod
    }
}

